<?php
/**
 * 恢复被清理的后端文件
 * 运行此脚本可以恢复所有被清理的文件
 */

$backupDir = __DIR__;
$basePath = __DIR__ . '/../../../app/';
$filesToRestore = array (
  0 => 'api/controller/AttributionController.php',
  1 => 'api/controller/DeviceController.php',
  2 => 'api/controller/MerchantController.php',
  3 => 'api/controller/TestController.php',
  4 => 'common/services/EmailService.php',
  5 => 'common/services/PushService.php',
  6 => 'common/services/AttributionService.php',
  7 => 'common/services/InvitationFreeInstallService.php',
  8 => 'common/model/AttributionEvent.php',
  9 => 'common/model/AttributionInstall.php',
  10 => 'common/model/AttributionTrack.php',
  11 => 'common/model/ChannelStats.php',
  12 => 'common/model/Device.php',
);

foreach ($filesToRestore as $file) {
    $sourcePath = $backupDir . '/' . $file;
    $targetPath = $basePath . $file;
    
    if (file_exists($sourcePath)) {
        // 创建目标目录
        $targetDir = dirname($targetPath);
        if (!is_dir($targetDir)) {
            mkdir($targetDir, 0755, true);
        }
        
        if (copy($sourcePath, $targetPath)) {
            echo "✅ 恢复成功: $file\n";
        } else {
            echo "❌ 恢复失败: $file\n";
        }
    } else {
        echo "⚠️  备份文件不存在: $file\n";
    }
}

echo "\n🎉 文件恢复完成！\n";
